﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Media.Imaging;

namespace Hangout.Client.Controls.User
{
    public partial class UserInfoWithoutScore : UserControl
    {
        public UserInfoWithoutScore()
        {
            InitializeComponent();
        }

        public event EventHandler ProfilePictureClicked;
        public event EventHandler StatusTextclicked;
        public event EventHandler ScoreClicked;
        public event EventHandler NameClicked;

        public MeetupService.MeetupData hangout;

        public MeetupService.MeetupData Hangout
        {
            get
            {
                try
                {
                    return hangout;
                }
                catch (Exception ex)
                {
                    Core.Exceptions.ExceptionReporting.Report(ex);
                    MessageBox.Show(ErrorText.GenericErrorText, ErrorText.GenericErrorCaption, MessageBoxButton.OK);
                    return new MeetupService.MeetupData();
                }
            }

            set
            {
                try
                {
                    hangout = value;
                    if (Hangout != null)
                    {
                        LoadHangoutData();
                    }
                }
                catch (Exception ex)
                {
                    Core.Exceptions.ExceptionReporting.Report(ex);
                    MessageBox.Show(ErrorText.GenericErrorText, ErrorText.GenericErrorCaption, MessageBoxButton.OK);
                    
                }
            }
        }

        private void LoadHangoutData()
        {
            try
            {
                if (Hangout != null)
                {
                    StatusLBL.Text = Hangout.Hangout.StatusText;
                }
            }
            catch (Exception ex)
            {
                Core.Exceptions.ExceptionReporting.Report(ex);
                MessageBox.Show(ErrorText.GenericErrorText, ErrorText.GenericErrorCaption, MessageBoxButton.OK);
            }
           
        }

       

        private AccountService.UserProfile profile;

        public AccountService.UserProfile Profile
        {
            
            get
            {
                try
                {
                    return profile;
                }
                catch (Exception ex)
                {
                    Core.Exceptions.ExceptionReporting.Report(ex);
                    MessageBox.Show(ErrorText.GenericErrorText, ErrorText.GenericErrorCaption, MessageBoxButton.OK);
                    return new AccountService.UserProfile();
                }

            }
            set
            {
                try
                {
                    profile = value;
                    if (Profile != null)
                    {
                        LoadData();
                    }
                }
                catch (Exception ex)
                {
                    Core.Exceptions.ExceptionReporting.Report(ex);
                    MessageBox.Show(ErrorText.GenericErrorText, ErrorText.GenericErrorCaption, MessageBoxButton.OK);
                }
            }
        
        }

        private void LoadData()
        {
            try
            {
                if (Profile != null)
                {
                    if (!String.IsNullOrWhiteSpace(Profile.User.Name))
                    {
                        NameLBL.Text = Profile.User.Name;
                    }
                    else
                    {
                        NameLBL.Text = "[NO NAME]";
                    }
                    LoadMyProfilePicture();

                }
            }
            catch (Exception ex)
            {
                Core.Exceptions.ExceptionReporting.Report(ex);
                MessageBox.Show(ErrorText.GenericErrorText, ErrorText.GenericErrorCaption, MessageBoxButton.OK);
            }
        }

        

        private void LoadMyProfilePicture()
        {
            try
            {
                if (!String.IsNullOrWhiteSpace(Profile.User.ProfilePicURL))
                {
                    MyProfilePicIMG.Source = new BitmapImage(new Uri(Profile.User.ProfilePicURL, UriKind.Absolute));
                }
            }
            catch (Exception ex)
            {
                Core.Exceptions.ExceptionReporting.Report(ex);
                MessageBox.Show(ErrorText.GenericErrorText, ErrorText.GenericErrorCaption, MessageBoxButton.OK);
            }
        }

        private void NameLBL_Tap(object sender, GestureEventArgs e)
        {
            try
            {
                if (NameClicked != null)
                {
                    NameClicked(null, new EventArgs());
                }
            }
            catch (Exception ex)
            {
                Core.Exceptions.ExceptionReporting.Report(ex);
                MessageBox.Show(ErrorText.GenericErrorText, ErrorText.GenericErrorCaption, MessageBoxButton.OK);
            }
        }

        private void StatusLBL_Tap(object sender, GestureEventArgs e)
        {
            try
            {
                if (Hangout != null)
                {
                    if (StatusTextclicked != null)
                    {
                        StatusTextclicked(null, new EventArgs());
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Exceptions.ExceptionReporting.Report(ex);
                MessageBox.Show(ErrorText.GenericErrorText, ErrorText.GenericErrorCaption, MessageBoxButton.OK);
            }
        }

        private void MyProfilePicIMG_Tap(object sender, GestureEventArgs e)
        {
            try
            {
                if (ProfilePictureClicked != null)
                {
                    ProfilePictureClicked(null, new EventArgs());
                }
            }
            catch (Exception ex)
            {
                Core.Exceptions.ExceptionReporting.Report(ex);
                MessageBox.Show(ErrorText.GenericErrorText, ErrorText.GenericErrorCaption, MessageBoxButton.OK);
            }
        }
    }
}
